package msg;

import static msg.xml.XMLTransformer.*;
import static org.junit.Assert.*;

import java.util.Arrays;

import msg.xml.XMLTransformer;

import org.junit.*;
import org.w3c.dom.Document;

import common.DALTests;

@SuppressWarnings({"javadoc"})
public class XMLTests extends DALTests {
	private Document		doc;
	private Message			msg;
	private EventMessage	event;
	
	@Before
	public void setupMessages() throws Exception {
		msg = new Message(0, new Location(32.77949, 35.011116), "Message content", getUser());
		event = new EventMessage(1, new Location(32.80055, 35.000854), "Event content", getUser(), getTomorrow(),
				10);
		doc = XMLTransformer.toXML(Arrays.asList(msg, event));
	}
	
	@Test
	public void testMessagesOnly() throws Exception {
		String expected = elementToString(XMLTransformer.toXML(Arrays.asList(msg)));
		String result = elementToString(XMLTransformer.toMessagesOnly(doc));
		assertEquals(expected, result);
	}
	
	@Test
	public void testEventsOnly() throws Exception {
		String expected = elementToString(XMLTransformer.toXML(Arrays.asList(event)));
		expected = expected.replace("MESSAGES", "EVENTS");
		String result = elementToString(XMLTransformer.toEventsOnly(doc));
		assertEquals(expected, result);
	}
	
	@Test
	public void testKML() throws Exception {
		elementToString(XMLTransformer.toKML(doc));
	}
}
